import Mock from 'mockjs'
import { deepClone } from '../../src/utils/index.js'
import { asyncRoutes, constantRoutes } from './routes.js'

const routes = deepClone([...constantRoutes, ...asyncRoutes])

const roles = [
  {
    id: 'admin',
    name: '超级管理员',
    kcode:'RA0001',
    description: '可以访问所有页面和权限',
    routes: routes
  },
  {
    id: 'editor',
    name: '运营管理员',
    kcode:'RA0002',
    description: '可以访问所有运营页面及学校页面',
    routes: routes.filter(i => i.path !== '/permission')// just a mock
    // routes: routes.filter(function(item) {
    //   // item.meta.role.some(i=> i.indexOf('editor')>=0) == true
    //
    //   console.log("11111=="+JSON.stringify(item))
    //   if(item.meta.hasOwnProperty('roles'))
    //     return true
    //
    //   let roles = item.meta.roles;
    //
    //
    //   return roles.some(rolename=>rolename.indexOf('editor')>=0)
    //
    // })// just a mock
  },
  {
    id: 'visitor',
    name: '校级管理员',
    kcode:'RA0003',
    description: '可以访问所有学校页面页面和权限',
    routes: [{
      path: '',
      redirect: 'dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          meta: { title: 'dashboard', icon: 'dashboard' }
        }
      ]
    }]
  }
]

export default [
  // mock get all routes form server
  {
    url: '/vue-admin-template/routes',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: routes
      }
    }
  },

  // mock get all roles form server
  {
    url: '/vue-admin-template/roles',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: roles
      }
    }
  },

  // add role
  {
    url: '/vue-admin-template/role',
    type: 'post',
    response: {
      code: 20000,
      data: {
        key: Mock.mock('@integer(100, 5000)')
      }
    }
  },

  // update role
  {
    url: '/vue-admin-template/role/[A-Za-z0-9]',
    type: 'put',
    response: {
      code: 20000,
      data: {
        status: 'success'
      }
    }
  },

  // delete role
  {
    url: '/vue-admin-template/role/[A-Za-z0-9]',
    type: 'delete',
    response: {
      code: 20000,
      data: {
        status: 'success'
      }
    }
  },

  // mock get all roles form server
  {
    url: '/vue-admin-template/organizes',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: []
      }
    }
  },

  // add role
  {
    url: '/vue-admin-template/organize',
    type: 'post',
    response: {
      code: 20000,
      data: {
        key: Mock.mock('@integer(300, 5000)')
      }
    }
  },

  // update role
  {
    url: '/vue-admin-template/organize/[A-Za-z0-9]',
    type: 'put',
    response: {
      code: 20000,
      data: {
        status: 'success'
      }
    }
  },

  // delete role
  {
    url: '/vue-admin-template/organize/[A-Za-z0-9]',
    type: 'delete',
    response: {
      code: 20000,
      data: {
        status: 'success'
      }
    }
  }
]
